//
//  NSString+Json.m
//  CharonTVProject
//
//  Created by karong on 2023/6/29.
//

#import "NSString+Json.h"

@implementation NSString (Json)

+ (NSString *)objectToJson:(id)obj {
    if (obj == nil) {
        return nil;
    }
    NSError * error = nil;
    NSData * jsonData = [NSJSONSerialization dataWithJSONObject:obj options:(NSJSONWritingPrettyPrinted) error:&error];
    if ([jsonData length] && error == nil) {
        return [[NSString alloc]initWithData:jsonData encoding:(NSUTF8StringEncoding)];
    }
    else {
        return nil;
    }
}

@end
